package 力扣日常刷题.木22一月.第05天0113;

/**
 * @author 帅小伙
 * @date 2022/1/13
 * @description
 */
public class Demo09回溯中等加减的目标值 {


    int ans = 0;
    public int findTargetSumWays(int[] nums, int target) {
        dfs(nums,0,target);
        return ans;
    }

    void dfs(int[] nums, int index,int target){
        if(index == nums.length && target == 0){
            ans ++;
            return;
        }
        if(index == nums.length) return;
        dfs(nums,index+1,target - nums[index]);
        dfs(nums,index+1,target + nums[index]);
    }

}
